home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / unlink < prev    next >
Text File  |  1996-11-09  |  2KB  |  90 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/unlink,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.3 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: unlink,v $
  10.  * Revision 1.3  1996/10/30 22:04:51  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.2  1996/05/06 09:01:35  unixlib
  14.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  15.  * Saved for 3.7a release.
  16.  *
  17.  * Revision 1.1  1996/04/19 21:35:27  simon
  18.  * Initial revision
  19.  *
  20.  * Complete re-write, 1994, Alun Jones.
  21.  ***************************************************************************/
  22.  
  23. static const char rcs_id[] = "$Id: unlink,v 1.3 1996/10/30 22:04:51 unixlib Rel $";
  24.  
  25. /* Fixes default of forcible deletions! */
  26.  
  27. #include <errno.h>
  28. #include <unistd.h>
  29. #include <sys/os.h>
  30. #include <sys/swis.h>
  31.  
  32. int
  33. unlink (char *file)
  34. {
  35.   int r[10];
  36.   _kernel_oserror *e;
  37.  
  38.   /* No filename given / no RISC OS equivalent
  39.    */
  40.   if (!*file)
  41.     {
  42.       errno = ENOENT;
  43.       return (-1);
  44.     }
  45.  
  46.   file = __uname (file, 0);
  47.  
  48.   /* Get file's catalogue entry (unfortunately
  49.    * uses wildcards. Still, shouldn't be a major problem)
  50.    */
  51.   r[0] = 17;
  52.   r[1] = (int) file;
  53.   if (e = os_swi (OS_File, r))
  54.     {
  55.       __seterr (e);
  56.       return (-1);
  57.     }
  58.  
  59.   /* What was the file's type ?
  60.    */
  61.   switch (r[0])
  62.     {
  63.     case 0:            /* Non-existent */
  64.       errno = ENOENT;
  65.       return (-1);
  66.     case 2:            /* Directory    */
  67.     case 3:            /* Image FS             */
  68.       errno = EISDIR;
  69.       return (-1);
  70.     default:            /* File                 */
  71.       break;
  72.     }
  73.  
  74.   /* Try to zap the file
  75.    */
  76.   r[0] = 6;
  77.   r[1] = (int) file;
  78.   if (e = os_swi (OS_File, r))
  79.     {
  80.       /* Should really check for EACCES and EROFS,
  81.        * but these errno's seem to float around for
  82.        * different FS's!
  83.        */
  84.       __seterr (e);
  85.       return (-1);
  86.     }
  87.  
  88.   return (0);
  89. }
  90.